const nodeMailer = require('nodemailer');
let mailConfig = require('../../../config/mailConfig');

function mailInfo(address, title, content) {
  return {
    from: mailConfig.from, // 发件地址
    to: address,
    subject: `${title}`, // 标题
    html: `<div>${content}</div>`,
  };
}

let mailClient = nodeMailer.createTransport(mailConfig);

function sendMail(address, title, content, callback) {
  if(mailConfig.openMailFunction) {
    mailClient.sendMail(mailInfo(address, title, content), callback);
  }
}

module.exports = sendMail;
